﻿using Newtonsoft.Json;
using Simple.Services;
using Simple.Services.System.Jobs;
using Simple.Services.System.Report.Violation;
using TaskStatus = Simple.Services.System.Jobs.TaskStatus;

namespace Simple.WebApi.Controllers.System;

/// <summary>
/// 违章报表分析
/// </summary>
[Route("QHSEiolationReport/[action]")]
[ApiController]
public class QHSEViolationReportController : ControllerBase
{
    private readonly QHSEViolationReportService _reportService;


    public QHSEViolationReportController(QHSEViolationReportService reportService)
    {
        _reportService = reportService;
    }
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public IActionResult CleanCompletedTasks()
    {

        // 将任务状态记录为 "进行中"
        var data = TaskManager.CleanCompletedTasks();

        // 返回任务 ID
        return Ok(new { data });
    }
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public IActionResult CleanFailedTasks()
    {

        // 将任务状态记录为 "进行中"
        var data = TaskManager.CleanFailedTasks();

        // 返回任务 ID
        return Ok(new { data });
    }
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public IActionResult StartTableViolationCheckCount([FromBody] QHSETotalInputModel model)
    {
        // 生成唯一任务 ID
        var taskId = Guid.NewGuid().ToString();

        // 将任务状态记录为 "进行中"
        TaskManager.AddTableTask(taskId, TaskStatus.Running, null);

        // 异步执行导出任务
        Task.Run(() => TableViolationCheckCountAsync(taskId, model));

        // 返回任务 ID
        return Ok(new { taskId });
    }
    private async Task TableViolationCheckCountAsync(string taskId, QHSETotalInputModel model)
    {
        try
        {
            // 调用生成 Excel 的方法
            var excelBytes = await _reportService.TableViolationTotalCheckCount(model);

            // 任务完成，更新状态为完成并保存生成的字节流
            TaskManager.CompleteTableTask(taskId, excelBytes);
        }
        catch (Exception ex)
        {
            // 任务失败，更新状态为失败并记录错误信息
            TaskManager.FailTableTask(taskId, ex.Message);
        }
    }
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public IActionResult GetTableViolationCheckCountStatus([FromBody] IdInputModel model)
    {
        // 获取任务状态
        var taskStatus = TaskManager.GetTaskTableStatus(model.Id);

        // 根据任务状态返回响应
        if (taskStatus.Status == TaskStatus.Completed)
        {
            // 任务完成，返回成功消息
            return Ok(new { status = "completed", model.Id });
        }
        else if (taskStatus.Status == TaskStatus.Failed)
        {
            return BadRequest(new { status = "failed", errorMessage = taskStatus.ErrorMessage });
        }
        else
        {
            // 任务正在进行中
            return Ok(new { status = "running" });
        }
    } 
    /// <summary>
    /// 报表-违章总数表格
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public async Task<AppResult> TakeTableViolationCheckCount([FromBody] IdInputModel model)
    {
        var tables = TaskManager.GetTaskTableStatus(model.Id);
        return AppResult.Status200OK(data: tables);
    }
    /// <summary>
    /// 报表-违章总数表格
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public async Task<AppResult> TableViolationCheckCount([FromBody] QHSETotalInputModel inputModel)
    {
        var res = await _reportService.TableViolationTotalCheckCount(inputModel);
        return AppResult.Status200OK(data: res);
    }
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public IActionResult StartCompareViolationCheckCount([FromBody] QHSEReportInputModel model)
    {
        // 生成唯一任务 ID
        var taskId = Guid.NewGuid().ToString();

        // 将任务状态记录为 "进行中"
        TaskManager.AddCompareTask(taskId, TaskStatus.Running, null);

        // 异步执行导出任务
        Task.Run(() => CompareViolationCheckCountAsync(taskId, model));

        // 返回任务 ID
        return Ok(new { taskId });
    }
    private async Task CompareViolationCheckCountAsync(string taskId, QHSEReportInputModel model)
    {
        try
        {
            // 调用生成 Excel 的方法
            var excelBytes = await _reportService.CompareViolationDepartmentCheckCount(model);

            // 任务完成，更新状态为完成并保存生成的字节流
            TaskManager.CompleteCompareTask(taskId, excelBytes);
        }
        catch (Exception ex)
        {
            // 任务失败，更新状态为失败并记录错误信息
            TaskManager.FailTableTask(taskId, ex.Message);
        }
    }
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public IActionResult GetCompareViolationCheckCountStatus([FromBody] IdInputModel model)
    {
        // 获取任务状态
        var taskStatus = TaskManager.GetTaskCompareStatus(model.Id);

        // 根据任务状态返回响应
        if (taskStatus.Status == TaskStatus.Completed)
        {
            // 任务完成，返回成功消息
            return Ok(new { status = "completed", model.Id });
        }
        else if (taskStatus.Status == TaskStatus.Failed)
        {
            return BadRequest(new { status = "failed", errorMessage = taskStatus.ErrorMessage });
        }
        else
        {
            // 任务正在进行中
            return Ok(new { status = "running" });
        }
    }
    /// <summary>
    /// 报表-违章查纠数量对比图
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public async Task<AppResult> TakeCompareViolationCheckCount([FromBody] IdInputModel model)
    {
        var tables = TaskManager.GetTaskCompareStatus(model.Id);
        return AppResult.Status200OK(data: tables);
    }
    /// <summary>
    /// 报表-违章查纠数量对比图
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public async Task<AppResult> CompareViolationCheckCount([FromBody] QHSEReportInputModel inputModel)
    {
        var res = await _reportService.CompareViolationDepartmentCheckCount(inputModel);
        return AppResult.Status200OK(data:res);
    }
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public IActionResult StartTabelSelfViolationCheckCount([FromBody] QHSEReportInputModel model)
    {
        // 生成唯一任务 ID
        var taskId = Guid.NewGuid().ToString();

        // 将任务状态记录为 "进行中"
        TaskManager.AddListCompareTask(taskId, TaskStatus.Running, null);

        // 异步执行导出任务
        Task.Run(() => TabelSelfViolationCheckCountAsync(taskId, model));

        // 返回任务 ID
        return Ok(new { taskId });
    }
    private async Task TabelSelfViolationCheckCountAsync(string taskId, QHSEReportInputModel model)
    {
        try
        {
            // 调用生成 Excel 的方法
            var excelBytes = await _reportService.TableViolationDepartmentCheckCount(model);

            // 任务完成，更新状态为完成并保存生成的字节流
            TaskManager.CompleteListCompareTask(taskId, excelBytes);
        }
        catch (Exception ex)
        {
            // 任务失败，更新状态为失败并记录错误信息
            TaskManager.FailListCompareTask(taskId, ex.Message);
        }
    }
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public IActionResult GetTabelSelfViolationCheckCountStatus([FromBody] IdInputModel model)
    {
        // 获取任务状态
        var taskStatus = TaskManager.GetTaskListCompareStatus(model.Id);

        // 根据任务状态返回响应
        if (taskStatus.Status == TaskStatus.Completed)
        {
            // 任务完成，返回成功消息
            return Ok(new { status = "completed", model.Id });
        }
        else if (taskStatus.Status == TaskStatus.Failed)
        {
            return BadRequest(new { status = "failed", errorMessage = taskStatus.ErrorMessage });
        }
        else
        {
            // 任务正在进行中
            return Ok(new { status = "running" });
        }
    }
    /// <summary>
    /// 报表-二级单位表格
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public async Task<AppResult> TakeTabelSelfViolationCheckCount([FromBody] IdInputModel model)
    {
        var tables = TaskManager.GetTaskListCompareStatus(model.Id);
        return AppResult.Status200OK(data: tables);
    }
    /// <summary>
    /// 报表-二级单位表格
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public async Task<AppResult> TabelSelfViolationCheckCount([FromBody] QHSEReportInputModel inputModel)
    {
        var res = await _reportService.TableViolationDepartmentCheckCount(inputModel);
        return AppResult.Status200OK(data: res);
    }
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public IActionResult StartCompareSelfViolationTypeCheckCount([FromBody] QHSEReportInputModel model)
    {
        // 生成唯一任务 ID
        var taskId = Guid.NewGuid().ToString();

        // 将任务状态记录为 "进行中"
        TaskManager.AddCompareTask(taskId, TaskStatus.Running, null);

        // 异步执行导出任务
        Task.Run(() => CompareSelfViolationTypeCheckCountAsync(taskId, model));

        // 返回任务 ID
        return Ok(new { taskId });
    }
    private async Task CompareSelfViolationTypeCheckCountAsync(string taskId, QHSEReportInputModel model)
    {
        try
        {
            // 调用生成 Excel 的方法
            var excelBytes = await _reportService.CompareSelfViolationTypeCheckCount(model);

            // 任务完成，更新状态为完成并保存生成的字节流
            TaskManager.CompleteCompareTask(taskId, excelBytes);
        }
        catch (Exception ex)
        {
            // 任务失败，更新状态为失败并记录错误信息
            TaskManager.FailCompareTask(taskId, ex.Message);
        }
    }
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public IActionResult GetCompareSelfViolationTypeCheckCountStatus([FromBody] IdInputModel model)
    {
        // 获取任务状态
        var taskStatus = TaskManager.GetTaskCompareStatus(model.Id);

        // 根据任务状态返回响应
        if (taskStatus.Status == TaskStatus.Completed)
        {
            // 任务完成，返回成功消息
            return Ok(new { status = "completed", model.Id });
        }
        else if (taskStatus.Status == TaskStatus.Failed)
        {
            return BadRequest(new { status = "failed", errorMessage = taskStatus.ErrorMessage });
        }
        else
        {
            // 任务正在进行中
            return Ok(new { status = "running" });
        }
    }
    /// <summary>
    /// 报表-违章级别对比-自查
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public async Task<AppResult> TakeCompareSelfViolationTypeCheckCount([FromBody] IdInputModel model)
    {
        var tables = TaskManager.GetTaskCompareStatus(model.Id);
        return AppResult.Status200OK(data: tables);
    }
    /// <summary>
    /// 报表-违章级别对比-自查
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public async Task<AppResult> CompareSelfViolationTypeCheckCount([FromBody] QHSEReportInputModel inputModel)
    {
        var res = await _reportService.CompareSelfViolationTypeCheckCount(inputModel);
        return AppResult.Status200OK(data: res);
    }
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public IActionResult StartCompareSuperviseViolationTypeCheckCount([FromBody] QHSEReportInputModel model)
    {
        // 生成唯一任务 ID
        var taskId = Guid.NewGuid().ToString();

        // 将任务状态记录为 "进行中"
        TaskManager.AddCompareTask(taskId, TaskStatus.Running, null);

        // 异步执行导出任务
        Task.Run(() => CompareSuperviseViolationTypeCheckCountAsync(taskId, model));

        // 返回任务 ID
        return Ok(new { taskId });
    }
    private async Task CompareSuperviseViolationTypeCheckCountAsync(string taskId, QHSEReportInputModel model)
    {
        try
        {
            // 调用生成 Excel 的方法
            var excelBytes = await _reportService.CompareSuperviseViolationTypeCheckCount(model);

            // 任务完成，更新状态为完成并保存生成的字节流
            TaskManager.CompleteCompareTask(taskId, excelBytes);
        }
        catch (Exception ex)
        {
            // 任务失败，更新状态为失败并记录错误信息
            TaskManager.FailCompareTask(taskId, ex.Message);
        }
    }
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public IActionResult GetCompareSuperviseViolationTypeCheckCountStatus([FromBody] IdInputModel model)
    {
        // 获取任务状态
        var taskStatus = TaskManager.GetTaskCompareStatus(model.Id);

        // 根据任务状态返回响应
        if (taskStatus.Status == TaskStatus.Completed)
        {
            // 任务完成，返回成功消息
            return Ok(new { status = "completed", model.Id });
        }
        else if (taskStatus.Status == TaskStatus.Failed)
        {
            return BadRequest(new { status = "failed", errorMessage = taskStatus.ErrorMessage });
        }
        else
        {
            // 任务正在进行中
            return Ok(new { status = "running" });
        }
    }
    /// <summary>
    /// 报表-违章级别对比-自查
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public async Task<AppResult> TakeCompareSuperviseViolationTypeCheckCount([FromBody] IdInputModel model)
    {
        var tables = TaskManager.GetTaskCompareStatus(model.Id);
        return AppResult.Status200OK(data: tables);
    }
    /// <summary>
    /// 报表-违章级别对比-监督
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public async Task<AppResult> CompareSuperviseViolationTypeCheckCount([FromBody] QHSEReportInputModel inputModel)
    {
        var res = await _reportService.CompareSuperviseViolationTypeCheckCount(inputModel);
        return AppResult.Status200OK(data: res);
    }
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public IActionResult StartTableViolationTypeCheckCount([FromBody] QHSEReportInputModel model)
    {
        // 生成唯一任务 ID
        var taskId = Guid.NewGuid().ToString();

        // 将任务状态记录为 "进行中"
        TaskManager.AddListTableTask(taskId, TaskStatus.Running, null);

        // 异步执行导出任务
        Task.Run(() => TableViolationTypeCheckCountAsync(taskId, model));

        // 返回任务 ID
        return Ok(new { taskId });
    }
    private async Task TableViolationTypeCheckCountAsync(string taskId, QHSEReportInputModel model)
    {
        try
        {
            // 调用生成 Excel 的方法
            var excelBytes = await _reportService.TableViolationTypeCheckCount(model);

            // 任务完成，更新状态为完成并保存生成的字节流
            TaskManager.CompleteListTableTask(taskId, excelBytes);
        }
        catch (Exception ex)
        {
            // 任务失败，更新状态为失败并记录错误信息
            TaskManager.FailListTableTask(taskId, ex.Message);
        }
    }
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public IActionResult GetTableViolationTypeCheckCountStatus([FromBody] IdInputModel model)
    {
        // 获取任务状态
        var taskStatus = TaskManager.GetTaskListTableStatus(model.Id);

        // 根据任务状态返回响应
        if (taskStatus.Status == TaskStatus.Completed)
        {
            // 任务完成，返回成功消息
            return Ok(new { status = "completed", model.Id });
        }
        else if (taskStatus.Status == TaskStatus.Failed)
        {
            return BadRequest(new { status = "failed", errorMessage = taskStatus.ErrorMessage });
        }
        else
        {
            // 任务正在进行中
            return Ok(new { status = "running" });
        }
    }
    /// <summary>
    /// 报表-违章级别对比-自查
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public async Task<AppResult> TakeTableViolationTypeCheckCount([FromBody] IdInputModel model)
    {
        var tables = TaskManager.GetTaskListTableStatus(model.Id);
        return AppResult.Status200OK(data: tables);
    }
    /// <summary>
    /// 报表-违章级别对比-表格
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public async Task<AppResult> TableViolationTypeCheckCount([FromBody] QHSEReportInputModel inputModel)
    {
        var res = await _reportService.TableViolationTypeCheckCount(inputModel);
        return AppResult.Status200OK(data: res);
    }
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public IActionResult StartCompareSelfViolationCategoryCheckCount([FromBody] QHSEReportInputModel model)
    {
        // 生成唯一任务 ID
        var taskId = Guid.NewGuid().ToString();

        // 将任务状态记录为 "进行中"
        TaskManager.AddCompareTask(taskId, TaskStatus.Running, null);

        // 异步执行导出任务
        Task.Run(() => CompareSelfViolationCategoryCheckCountAsync(taskId, model));

        // 返回任务 ID
        return Ok(new { taskId });
    }
    private async Task CompareSelfViolationCategoryCheckCountAsync(string taskId, QHSEReportInputModel model)
    {
        try
        {
            // 调用生成 Excel 的方法
            var excelBytes = await _reportService.CompareSelfViolationCategoryCheckCount(model);

            // 任务完成，更新状态为完成并保存生成的字节流
            TaskManager.CompleteCompareTask(taskId, excelBytes);
        }
        catch (Exception ex)
        {
            // 任务失败，更新状态为失败并记录错误信息
            TaskManager.FailCompareTask(taskId, ex.Message);
        }
    }
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public IActionResult GetCompareSelfViolationCategoryCheckCountStatus([FromBody] IdInputModel model)
    {
        // 获取任务状态
        var taskStatus = TaskManager.GetTaskCompareStatus(model.Id);

        // 根据任务状态返回响应
        if (taskStatus.Status == TaskStatus.Completed)
        {
            // 任务完成，返回成功消息
            return Ok(new { status = "completed", model.Id });
        }
        else if (taskStatus.Status == TaskStatus.Failed)
        {
            return BadRequest(new { status = "failed", errorMessage = taskStatus.ErrorMessage });
        }
        else
        {
            // 任务正在进行中
            return Ok(new { status = "running" });
        }
    }
    /// <summary>
    /// 报表-违章级别对比-自查
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public async Task<AppResult> TakeCompareSelfViolationCategoryCheckCount([FromBody] IdInputModel model)
    {
        var tables = TaskManager.GetTaskCompareStatus(model.Id);
        return AppResult.Status200OK(data: tables);
    }
    /// <summary>
    /// 报表-违章类别对比-自查
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public async Task<AppResult> CompareSelfViolationCategoryCheckCount([FromBody] QHSEReportInputModel inputModel)
    {
        var res = await _reportService.CompareSelfViolationCategoryCheckCount(inputModel);
        return AppResult.Status200OK(data: res);
    }
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public IActionResult StartCompareSuperviseViolationCategoryCheckCount([FromBody] QHSEReportInputModel model)
    {
        // 生成唯一任务 ID
        var taskId = Guid.NewGuid().ToString();

        // 将任务状态记录为 "进行中"
        TaskManager.AddCompareTask(taskId, TaskStatus.Running, null);

        // 异步执行导出任务
        Task.Run(() => CompareSuperviseViolationCategoryCheckCountAsync(taskId, model));

        // 返回任务 ID
        return Ok(new { taskId });
    }
    private async Task CompareSuperviseViolationCategoryCheckCountAsync(string taskId, QHSEReportInputModel model)
    {
        try
        {
            // 调用生成 Excel 的方法
            var excelBytes = await _reportService.CompareSuperviseViolationCategoryCheckCount(model);

            // 任务完成，更新状态为完成并保存生成的字节流
            TaskManager.CompleteCompareTask(taskId, excelBytes);
        }
        catch (Exception ex)
        {
            // 任务失败，更新状态为失败并记录错误信息
            TaskManager.FailCompareTask(taskId, ex.Message);
        }
    }
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public IActionResult GetCompareSuperviseViolationCategoryCheckCountStatus([FromBody] IdInputModel model)
    {
        // 获取任务状态
        var taskStatus = TaskManager.GetTaskCompareStatus(model.Id);

        // 根据任务状态返回响应
        if (taskStatus.Status == TaskStatus.Completed)
        {
            // 任务完成，返回成功消息
            return Ok(new { status = "completed", model.Id });
        }
        else if (taskStatus.Status == TaskStatus.Failed)
        {
            return BadRequest(new { status = "failed", errorMessage = taskStatus.ErrorMessage });
        }
        else
        {
            // 任务正在进行中
            return Ok(new { status = "running" });
        }
    }
    /// <summary>
    /// 报表-违章类别对比-监督
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public async Task<AppResult> TakeCompareSuperviseViolationCategoryCheckCount([FromBody] IdInputModel model)
    {
        var tables = TaskManager.GetTaskCompareStatus(model.Id);
        return AppResult.Status200OK(data: tables);
    }
    /// <summary>
    /// 报表-违章类别对比-监督
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public async Task<AppResult> CompareSuperviseViolationCategoryCheckCount([FromBody] QHSEReportInputModel inputModel)
    {
        var res = await _reportService.CompareSuperviseViolationCategoryCheckCount(inputModel);
        return AppResult.Status200OK(data: res);
    }
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public IActionResult StartTableViolationCategoryCheckCount([FromBody] QHSEReportInputModel model)
    {
        // 生成唯一任务 ID
        var taskId = Guid.NewGuid().ToString();

        // 将任务状态记录为 "进行中"
        TaskManager.AddListTableTask(taskId, TaskStatus.Running, null);

        // 异步执行导出任务
        Task.Run(() => TableViolationCategoryCheckCountAsync(taskId, model));

        // 返回任务 ID
        return Ok(new { taskId });
    }
    private async Task TableViolationCategoryCheckCountAsync(string taskId, QHSEReportInputModel model)
    {
        try
        {
            // 调用生成 Excel 的方法
            var excelBytes = await _reportService.TableViolationCategoryCheckCount(model);

            // 任务完成，更新状态为完成并保存生成的字节流
            TaskManager.CompleteListTableTask(taskId, excelBytes);
        }
        catch (Exception ex)
        {
            // 任务失败，更新状态为失败并记录错误信息
            TaskManager.FailListTableTask(taskId, ex.Message);
        }
    }
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public IActionResult GetTableViolationCategoryCheckCountStatus([FromBody] IdInputModel model)
    {
        // 获取任务状态
        var taskStatus = TaskManager.GetTaskListTableStatus(model.Id);

        // 根据任务状态返回响应
        if (taskStatus.Status == TaskStatus.Completed)
        {
            // 任务完成，返回成功消息
            return Ok(new { status = "completed", model.Id });
        }
        else if (taskStatus.Status == TaskStatus.Failed)
        {
            return BadRequest(new { status = "failed", errorMessage = taskStatus.ErrorMessage });
        }
        else
        {
            // 任务正在进行中
            return Ok(new { status = "running" });
        }
    }
    /// <summary>
    /// 报表-违章类别对比-表格
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public async Task<AppResult> TakeTableViolationCategoryCheckCount([FromBody] IdInputModel model)
    {
        var tables = TaskManager.GetTaskListTableStatus(model.Id);
        return AppResult.Status200OK(data: tables);
    }
    /// <summary>
    /// 报表-违章类别对比-表格
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public async Task<AppResult> TableViolationCategoryCheckCount([FromBody] QHSEReportInputModel inputModel)
    {
        var res = await _reportService.TableViolationCategoryCheckCount(inputModel);
        return AppResult.Status200OK(data: res);
    }
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public IActionResult StartCompareSelfViolationWorkYearsCheckCount([FromBody] QHSEReportInputModel model)
    {
        // 生成唯一任务 ID
        var taskId = Guid.NewGuid().ToString();

        // 将任务状态记录为 "进行中"
        TaskManager.AddCompareTask(taskId, TaskStatus.Running, null);

        // 异步执行导出任务
        Task.Run(() => CompareSelfViolationWorkYearsCheckCountAsync(taskId, model));

        // 返回任务 ID
        return Ok(new { taskId });
    }
    private async Task CompareSelfViolationWorkYearsCheckCountAsync(string taskId, QHSEReportInputModel model)
    {
        try
        {
            // 调用生成 Excel 的方法
            var excelBytes = await _reportService.CompareSelfViolationAgeCheckCount(model);

            // 任务完成，更新状态为完成并保存生成的字节流
            TaskManager.CompleteCompareTask(taskId, excelBytes);
        }
        catch (Exception ex)
        {
            // 任务失败，更新状态为失败并记录错误信息
            TaskManager.FailCompareTask(taskId, ex.Message);
        }
    }
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public IActionResult GetCompareSelfViolationWorkYearsCheckCountStatus([FromBody] IdInputModel model)
    {
        // 获取任务状态
        var taskStatus = TaskManager.GetTaskCompareStatus(model.Id);

        // 根据任务状态返回响应
        if (taskStatus.Status == TaskStatus.Completed)
        {
            // 任务完成，返回成功消息
            return Ok(new { status = "completed", model.Id });
        }
        else if (taskStatus.Status == TaskStatus.Failed)
        {
            return BadRequest(new { status = "failed", errorMessage = taskStatus.ErrorMessage });
        }
        else
        {
            // 任务正在进行中
            return Ok(new { status = "running" });
        }
    }
    /// <summary>
    /// 报表-违章工龄对比-自查
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public async Task<AppResult> TakeCompareSelfViolationWorkYearsCheckCount([FromBody] IdInputModel model)
    {
        var tables = TaskManager.GetTaskCompareStatus(model.Id);
        return AppResult.Status200OK(data: tables);
    }
    /// <summary>
    /// 报表-违章工龄对比-自查
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public async Task<AppResult> CompareSelfViolationWorkYearsCheckCount([FromBody] QHSEReportInputModel inputModel)
    {
        var res = await _reportService.CompareSelfViolationAgeCheckCount(inputModel);
        return AppResult.Status200OK(data: res);
    }
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public IActionResult StartCompareSuperviseViolationWorkYearsCheckCount([FromBody] QHSEReportInputModel model)
    {
        // 生成唯一任务 ID
        var taskId = Guid.NewGuid().ToString();

        // 将任务状态记录为 "进行中"
        TaskManager.AddCompareTask(taskId, TaskStatus.Running, null);

        // 异步执行导出任务
        Task.Run(() => CompareSuperviseViolationWorkYearsCheckCountAsync(taskId, model));

        // 返回任务 ID
        return Ok(new { taskId });
    }
    private async Task CompareSuperviseViolationWorkYearsCheckCountAsync(string taskId, QHSEReportInputModel model)
    {
        try
        {
            // 调用生成 Excel 的方法
            var excelBytes = await _reportService.CompareSuperviseViolationAgeCheckCount(model);

            // 任务完成，更新状态为完成并保存生成的字节流
            TaskManager.CompleteCompareTask(taskId, excelBytes);
        }
        catch (Exception ex)
        {
            // 任务失败，更新状态为失败并记录错误信息
            TaskManager.FailCompareTask(taskId, ex.Message);
        }
    }
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public IActionResult GetCompareSuperviseViolationWorkYearsCheckCountStatus([FromBody] IdInputModel model)
    {
        // 获取任务状态
        var taskStatus = TaskManager.GetTaskCompareStatus(model.Id);

        // 根据任务状态返回响应
        if (taskStatus.Status == TaskStatus.Completed)
        {
            // 任务完成，返回成功消息
            return Ok(new { status = "completed", model.Id });
        }
        else if (taskStatus.Status == TaskStatus.Failed)
        {
            return BadRequest(new { status = "failed", errorMessage = taskStatus.ErrorMessage });
        }
        else
        {
            // 任务正在进行中
            return Ok(new { status = "running" });
        }
    }
    /// <summary>
    /// 报表-违章工龄对比-监督
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public async Task<AppResult> TakeCompareSuperviseViolationWorkYearsCheckCount([FromBody] IdInputModel model)
    {
        var tables = TaskManager.GetTaskCompareStatus(model.Id);
        return AppResult.Status200OK(data: tables);
    }
    /// <summary>
    /// 报表-违章工龄对比-监督
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public async Task<AppResult> CompareSuperviseViolationWorkYearsCheckCount([FromBody] QHSEReportInputModel inputModel)
    {
        var res = await _reportService.CompareSuperviseViolationAgeCheckCount(inputModel);
        return AppResult.Status200OK(data: res);
    }
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public IActionResult StartTableViolationWorkYearsCheckCount([FromBody] QHSEReportInputModel model)
    {
        // 生成唯一任务 ID
        var taskId = Guid.NewGuid().ToString();

        // 将任务状态记录为 "进行中"
        TaskManager.AddListTableTask(taskId, TaskStatus.Running, null);

        // 异步执行导出任务
        Task.Run(() => TableViolationWorkYearsCheckCountAsync(taskId, model));

        // 返回任务 ID
        return Ok(new { taskId });
    }
    private async Task TableViolationWorkYearsCheckCountAsync(string taskId, QHSEReportInputModel model)
    {
        try
        {
            // 调用生成 Excel 的方法
            var excelBytes = await _reportService.TableViolationAgeCheckCount(model);

            // 任务完成，更新状态为完成并保存生成的字节流
            TaskManager.CompleteListTableTask(taskId, excelBytes);
        }
        catch (Exception ex)
        {
            // 任务失败，更新状态为失败并记录错误信息
            TaskManager.FailListTableTask(taskId, ex.Message);
        }
    }
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public IActionResult GetTableViolationWorkYearsCheckCountStatus([FromBody] IdInputModel model)
    {
        // 获取任务状态
        var taskStatus = TaskManager.GetTaskListTableStatus(model.Id);

        // 根据任务状态返回响应
        if (taskStatus.Status == TaskStatus.Completed)
        {
            // 任务完成，返回成功消息
            return Ok(new { status = "completed", model.Id });
        }
        else if (taskStatus.Status == TaskStatus.Failed)
        {
            return BadRequest(new { status = "failed", errorMessage = taskStatus.ErrorMessage });
        }
        else
        {
            // 任务正在进行中
            return Ok(new { status = "running" });
        }
    }
    /// <summary>
    /// 报表-违章工龄对比-表格
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public async Task<AppResult> TakeTableViolationWorkYearsCheckCount([FromBody] IdInputModel model)
    {
        var tables = TaskManager.GetTaskListTableStatus(model.Id);
        return AppResult.Status200OK(data: tables);
    }
    /// <summary>
    /// 报表-违章工龄对比-表格
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public async Task<AppResult> TableViolationWorkYearsCheckCount([FromBody] QHSEReportInputModel inputModel)
    {
        var res = await _reportService.TableViolationAgeCheckCount(inputModel);
        return AppResult.Status200OK(data: res);
    }
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public IActionResult StartCompareSuperviseViolationDepartmentCheckCount([FromBody] QHSEReportInputModel model)
    {
        // 生成唯一任务 ID
        var taskId = Guid.NewGuid().ToString();

        // 将任务状态记录为 "进行中"
        TaskManager.AddCompareTask(taskId, TaskStatus.Running, null);

        // 异步执行导出任务
        Task.Run(() => CompareSuperviseViolationDepartmentCheckCountAsync(taskId, model));

        // 返回任务 ID
        return Ok(new { taskId });
    }
    private async Task CompareSuperviseViolationDepartmentCheckCountAsync(string taskId, QHSEReportInputModel model)
    {
        try
        {
            // 调用生成 Excel 的方法
            var excelBytes = await _reportService.CompareSuperviseViolationDepartmentCheckCount(model);

            // 任务完成，更新状态为完成并保存生成的字节流
            TaskManager.CompleteCompareTask(taskId, excelBytes);
        }
        catch (Exception ex)
        {
            // 任务失败，更新状态为失败并记录错误信息
            TaskManager.FailCompareTask(taskId, ex.Message);
        }
    }
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public IActionResult GetCompareSuperviseViolationDepartmentCheckCountStatus([FromBody] IdInputModel model)
    {
        // 获取任务状态
        var taskStatus = TaskManager.GetTaskCompareStatus(model.Id);

        // 根据任务状态返回响应
        if (taskStatus.Status == TaskStatus.Completed)
        {
            // 任务完成，返回成功消息
            return Ok(new { status = "completed", model.Id });
        }
        else if (taskStatus.Status == TaskStatus.Failed)
        {
            return BadRequest(new { status = "failed", errorMessage = taskStatus.ErrorMessage });
        }
        else
        {
            // 任务正在进行中
            return Ok(new { status = "running" });
        }
    }
    /// <summary>
    /// 报表-违章归属部门对比-监督
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public async Task<AppResult> TakeCompareSuperviseViolationDepartmentCheckCount([FromBody] IdInputModel model)
    {
        var tables = TaskManager.GetTaskCompareStatus(model.Id);
        return AppResult.Status200OK(data: tables);
    }
    /// <summary>
    /// 报表-违章归属部门对比-监督
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public async Task<AppResult> CompareSuperviseViolationDepartmentsCheckCount([FromBody] QHSEReportInputModel inputModel)
    {
        var res = await _reportService.CompareSuperviseViolationDepartmentCheckCount(inputModel);
        return AppResult.Status200OK(data: res);
    }
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public IActionResult StartTableTableViolationDirectDepartmentCheckCount([FromBody] QHSEReportInputModel model)
    {
        // 生成唯一任务 ID
        var taskId = Guid.NewGuid().ToString();

        // 将任务状态记录为 "进行中"
        TaskManager.AddListTableTask(taskId, TaskStatus.Running, null);

        // 异步执行导出任务
        Task.Run(() => TableViolationDirectDepartmentCheckCountAsync(taskId, model));

        // 返回任务 ID
        return Ok(new { taskId });
    }
    private async Task TableViolationDirectDepartmentCheckCountAsync(string taskId, QHSEReportInputModel model)
    {
        try
        {
            // 调用生成 Excel 的方法
            var excelBytes = await _reportService.TableViolationDirectDepartmentCheckCount(model);

            // 任务完成，更新状态为完成并保存生成的字节流
            TaskManager.CompleteListTableTask(taskId, excelBytes);
        }
        catch (Exception ex)
        {
            // 任务失败，更新状态为失败并记录错误信息
            TaskManager.FailListTableTask(taskId, ex.Message);
        }
    }
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public IActionResult GetTableViolationDirectDepartmentCheckCountStatus([FromBody] IdInputModel model)
    {
        // 获取任务状态
        var taskStatus = TaskManager.GetTaskListTableStatus(model.Id);

        // 根据任务状态返回响应
        if (taskStatus.Status == TaskStatus.Completed)
        {
            // 任务完成，返回成功消息
            return Ok(new { status = "completed", model.Id });
        }
        else if (taskStatus.Status == TaskStatus.Failed)
        {
            return BadRequest(new { status = "failed", errorMessage = taskStatus.ErrorMessage });
        }
        else
        {
            // 任务正在进行中
            return Ok(new { status = "running" });
        }
    }
    /// <summary>
    /// 报表-违章归属部门对比-表格
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public async Task<AppResult> TakeTableViolationDirectDepartmentCheckCount([FromBody] IdInputModel model)
    {
        var tables = TaskManager.GetTaskListTableStatus(model.Id);
        return AppResult.Status200OK(data: tables);
    }
    /// <summary>
    /// 报表-违章归属部门对比-表格
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public async Task<AppResult> TableViolationDirectDepartmentCheckCount([FromBody] QHSEReportInputModel inputModel)
    {
        var res = await _reportService.TableViolationDirectDepartmentCheckCount(inputModel);
        return AppResult.Status200OK(data: res);
    }
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public IActionResult StartCompareSelfViolationWorkSpecialtyCheckCount([FromBody] QHSEReportInputModel model)
    {
        // 生成唯一任务 ID
        var taskId = Guid.NewGuid().ToString();

        // 将任务状态记录为 "进行中"
        TaskManager.AddCompareTask(taskId, TaskStatus.Running, null);

        // 异步执行导出任务
        Task.Run(() => CompareSelfViolationWorkSpecialtyCheckCountAsync(taskId, model));

        // 返回任务 ID
        return Ok(new { taskId });
    }
    private async Task CompareSelfViolationWorkSpecialtyCheckCountAsync(string taskId, QHSEReportInputModel model)
    {
        try
        {
            // 调用生成 Excel 的方法
            var excelBytes = await _reportService.CompareSelfViolationWorkSpecialtyCheckCount(model);

            // 任务完成，更新状态为完成并保存生成的字节流
            TaskManager.CompleteCompareTask(taskId, excelBytes);
        }
        catch (Exception ex)
        {
            // 任务失败，更新状态为失败并记录错误信息
            TaskManager.FailCompareTask(taskId, ex.Message);
        }
    }
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public IActionResult GetCompareSelfViolationWorkSpecialtyCheckCountStatus([FromBody] IdInputModel model)
    {
        // 获取任务状态
        var taskStatus = TaskManager.GetTaskCompareStatus(model.Id);

        // 根据任务状态返回响应
        if (taskStatus.Status == TaskStatus.Completed)
        {
            // 任务完成，返回成功消息
            return Ok(new { status = "completed", model.Id });
        }
        else if (taskStatus.Status == TaskStatus.Failed)
        {
            return BadRequest(new { status = "failed", errorMessage = taskStatus.ErrorMessage });
        }
        else
        {
            // 任务正在进行中
            return Ok(new { status = "running" });
        }
    }
    /// <summary>
    /// 报表-违章专业对比-自查
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public async Task<AppResult> TakeCompareSelfViolationWorkSpecialtyCheckCount([FromBody] IdInputModel model)
    {
        var tables = TaskManager.GetTaskCompareStatus(model.Id);
        return AppResult.Status200OK(data: tables);
    }
    /// <summary>
    /// 报表-违章专业对比-自查
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public async Task<AppResult> CompareSelfViolationWorkSpecialtyCheckCount([FromBody] QHSEReportInputModel inputModel)
    {
        var res = await _reportService.CompareSelfViolationWorkSpecialtyCheckCount(inputModel);
        return AppResult.Status200OK(data: res);
    }
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public IActionResult StartCompareSuperviseViolationWorkSpecialtyCheckCount([FromBody] QHSEReportInputModel model)
    {
        // 生成唯一任务 ID
        var taskId = Guid.NewGuid().ToString();

        // 将任务状态记录为 "进行中"
        TaskManager.AddCompareTask(taskId, TaskStatus.Running, null);

        // 异步执行导出任务
        Task.Run(() => CompareSuperviseViolationWorkSpecialtyCheckCountAsync(taskId, model));

        // 返回任务 ID
        return Ok(new { taskId });
    }
    private async Task CompareSuperviseViolationWorkSpecialtyCheckCountAsync(string taskId, QHSEReportInputModel model)
    {
        try
        {
            // 调用生成 Excel 的方法
            var excelBytes = await _reportService.CompareSuperviseViolationWorkSpecialtyCheckCount(model);

            // 任务完成，更新状态为完成并保存生成的字节流
            TaskManager.CompleteCompareTask(taskId, excelBytes);
        }
        catch (Exception ex)
        {
            // 任务失败，更新状态为失败并记录错误信息
            TaskManager.FailCompareTask(taskId, ex.Message);
        }
    }
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public IActionResult GetCompareSuperviseViolationWorkSpecialtyCheckCountStatus([FromBody] IdInputModel model)
    {
        // 获取任务状态
        var taskStatus = TaskManager.GetTaskCompareStatus(model.Id);

        // 根据任务状态返回响应
        if (taskStatus.Status == TaskStatus.Completed)
        {
            // 任务完成，返回成功消息
            return Ok(new { status = "completed", model.Id });
        }
        else if (taskStatus.Status == TaskStatus.Failed)
        {
            return BadRequest(new { status = "failed", errorMessage = taskStatus.ErrorMessage });
        }
        else
        {
            // 任务正在进行中
            return Ok(new { status = "running" });
        }
    }
    /// <summary>
    /// 报表-违章专业对比-监督
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public async Task<AppResult> TakeCompareSuperviseViolationWorkSpecialtyCheckCount([FromBody] IdInputModel model)
    {
        var tables = TaskManager.GetTaskCompareStatus(model.Id);
        return AppResult.Status200OK(data: tables);
    }
    /// <summary>
    /// 报表-违章专业对比-监督
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public async Task<AppResult> CompareSuperviseViolationWorkSpecialtyCheckCount([FromBody] QHSEReportInputModel inputModel)
    {
        var res = await _reportService.CompareSuperviseViolationWorkSpecialtyCheckCount(inputModel);
        return AppResult.Status200OK(data: res);
    }
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public IActionResult StartTableViolationWorkSpecialtyCheckCount([FromBody] QHSEReportInputModel model)
    {
        // 生成唯一任务 ID
        var taskId = Guid.NewGuid().ToString();

        // 将任务状态记录为 "进行中"
        TaskManager.AddListTableTask(taskId, TaskStatus.Running, null);

        // 异步执行导出任务
        Task.Run(() => TableViolationWorkSpecialtyCheckCountAsync(taskId, model));

        // 返回任务 ID
        return Ok(new { taskId });
    }
    private async Task TableViolationWorkSpecialtyCheckCountAsync(string taskId, QHSEReportInputModel model)
    {
        try
        {
            // 调用生成 Excel 的方法
            var excelBytes = await _reportService.TableViolationSpecialtyCheckCount(model);

            // 任务完成，更新状态为完成并保存生成的字节流
            TaskManager.CompleteListTableTask(taskId, excelBytes);
        }
        catch (Exception ex)
        {
            // 任务失败，更新状态为失败并记录错误信息
            TaskManager.FailListTableTask(taskId, ex.Message);
        }
    }
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public IActionResult GetTableViolationWorkSpecialtyCheckCountStatus([FromBody] IdInputModel model)
    {
        // 获取任务状态
        var taskStatus = TaskManager.GetTaskListTableStatus(model.Id);

        // 根据任务状态返回响应
        if (taskStatus.Status == TaskStatus.Completed)
        {
            // 任务完成，返回成功消息
            return Ok(new { status = "completed", model.Id });
        }
        else if (taskStatus.Status == TaskStatus.Failed)
        {
            return BadRequest(new { status = "failed", errorMessage = taskStatus.ErrorMessage });
        }
        else
        {
            // 任务正在进行中
            return Ok(new { status = "running" });
        }
    }
    /// <summary>
    /// 报表-违章专业对比-表格
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public async Task<AppResult> TakeTableViolationWorkSpecialtyCheckCount([FromBody] IdInputModel model)
    {
        var tables = TaskManager.GetTaskListTableStatus(model.Id);
        return AppResult.Status200OK(data: tables);
    }
    /// <summary>
    /// 报表-违章专业对比-表格
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public async Task<AppResult> TableViolationWorkSpecialtyCheckCount([FromBody] QHSEReportInputModel inputModel)
    {
        var res = await _reportService.TableViolationSpecialtyCheckCount(inputModel);
        return AppResult.Status200OK(data: res);
    }
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public IActionResult StartCompareSelfViolationKeyWorkCheckCount([FromBody] QHSEReportInputModel model)
    {
        // 生成唯一任务 ID
        var taskId = Guid.NewGuid().ToString();

        // 将任务状态记录为 "进行中"
        TaskManager.AddCompareTask(taskId, TaskStatus.Running, null);

        // 异步执行导出任务
        Task.Run(() => CompareSelfViolationKeyWorkCheckCountAsync(taskId, model));

        // 返回任务 ID
        return Ok(new { taskId });
    }
    private async Task CompareSelfViolationKeyWorkCheckCountAsync(string taskId, QHSEReportInputModel model)
    {
        try
        {
            // 调用生成 Excel 的方法
            var excelBytes = await _reportService.CompareSelfViolationKeyWorkCheckCount(model);

            // 任务完成，更新状态为完成并保存生成的字节流
            TaskManager.CompleteCompareTask(taskId, excelBytes);
        }
        catch (Exception ex)
        {
            // 任务失败，更新状态为失败并记录错误信息
            TaskManager.FailCompareTask(taskId, ex.Message);
        }
    }
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public IActionResult GetCompareSelfViolationKeyWorkCheckCountStatus([FromBody] IdInputModel model)
    {
        // 获取任务状态
        var taskStatus = TaskManager.GetTaskCompareStatus(model.Id);

        // 根据任务状态返回响应
        if (taskStatus.Status == TaskStatus.Completed)
        {
            // 任务完成，返回成功消息
            return Ok(new { status = "completed", model.Id });
        }
        else if (taskStatus.Status == TaskStatus.Failed)
        {
            return BadRequest(new { status = "failed", errorMessage = taskStatus.ErrorMessage });
        }
        else
        {
            // 任务正在进行中
            return Ok(new { status = "running" });
        }
    }
    /// <summary>
    /// 报表-违章关键作业对比-自查
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public async Task<AppResult> TakeCompareSelfViolationKeyWorkCheckCount([FromBody] IdInputModel model)
    {
        var tables = TaskManager.GetTaskCompareStatus(model.Id);
        return AppResult.Status200OK(data: tables);
    }
    /// <summary>
    /// 报表-违章关键作业对比-自查
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public async Task<AppResult> CompareSelfViolationKeyWorkCheckCount([FromBody] QHSEReportInputModel inputModel)
    {
        var res = await _reportService.CompareSelfViolationKeyWorkCheckCount(inputModel);
        return AppResult.Status200OK(data: res);
    }
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public IActionResult StartCompareSuperviseViolationKeyWorkCheckCount([FromBody] QHSEReportInputModel model)
    {
        // 生成唯一任务 ID
        var taskId = Guid.NewGuid().ToString();

        // 将任务状态记录为 "进行中"
        TaskManager.AddCompareTask(taskId, TaskStatus.Running, null);

        // 异步执行导出任务
        Task.Run(() => CompareSuperviseViolationKeyWorkCheckCountAsync(taskId, model));

        // 返回任务 ID
        return Ok(new { taskId });
    }
    private async Task CompareSuperviseViolationKeyWorkCheckCountAsync(string taskId, QHSEReportInputModel model)
    {
        try
        {
            // 调用生成 Excel 的方法
            var excelBytes = await _reportService.CompareSuperviseViolationKeyWorkCheckCount(model);

            // 任务完成，更新状态为完成并保存生成的字节流
            TaskManager.CompleteCompareTask(taskId, excelBytes);
        }
        catch (Exception ex)
        {
            // 任务失败，更新状态为失败并记录错误信息
            TaskManager.FailCompareTask(taskId, ex.Message);
        }
    }
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public IActionResult GetCompareSuperviseViolationKeyWorkCheckCountStatus([FromBody] IdInputModel model)
    {
        // 获取任务状态
        var taskStatus = TaskManager.GetTaskCompareStatus(model.Id);

        // 根据任务状态返回响应
        if (taskStatus.Status == TaskStatus.Completed)
        {
            // 任务完成，返回成功消息
            return Ok(new { status = "completed", model.Id });
        }
        else if (taskStatus.Status == TaskStatus.Failed)
        {
            return BadRequest(new { status = "failed", errorMessage = taskStatus.ErrorMessage });
        }
        else
        {
            // 任务正在进行中
            return Ok(new { status = "running" });
        }
    }
    /// <summary>
    /// 报表-违章关键作业对比-监督
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public async Task<AppResult> TakeCompareSuperviseViolationKeyWorkCheckCount([FromBody] IdInputModel model)
    {
        var tables = TaskManager.GetTaskCompareStatus(model.Id);
        return AppResult.Status200OK(data: tables);
    }
    /// <summary>
    /// 报表-违章关键作业对比-监督
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public async Task<AppResult> CompareSuperviseViolationKeyWorkCheckCount([FromBody] QHSEReportInputModel inputModel)
    {
        var res = await _reportService.CompareSuperviseViolationKeyWorkCheckCount(inputModel);
        return AppResult.Status200OK(data: res);
    }
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public IActionResult StartTableViolationKeyWorkCheckCount([FromBody] QHSEReportInputModel model)
    {
        // 生成唯一任务 ID
        var taskId = Guid.NewGuid().ToString();

        // 将任务状态记录为 "进行中"
        TaskManager.AddListTableTask(taskId, TaskStatus.Running, null);

        // 异步执行导出任务
        Task.Run(() => TableViolationKeyWorkCheckCountAsync(taskId, model));

        // 返回任务 ID
        return Ok(new { taskId });
    }
    private async Task TableViolationKeyWorkCheckCountAsync(string taskId, QHSEReportInputModel model)
    {
        try
        {
            // 调用生成 Excel 的方法
            var excelBytes = await _reportService.TableViolationWorkTypeCheckCount(model);

            // 任务完成，更新状态为完成并保存生成的字节流
            TaskManager.CompleteListTableTask(taskId, excelBytes);
        }
        catch (Exception ex)
        {
            // 任务失败，更新状态为失败并记录错误信息
            TaskManager.FailListTableTask(taskId, ex.Message);
        }
    }
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public IActionResult GetTableViolationKeyWorkCheckCountStatus([FromBody] IdInputModel model)
    {
        // 获取任务状态
        var taskStatus = TaskManager.GetTaskListTableStatus(model.Id);

        // 根据任务状态返回响应
        if (taskStatus.Status == TaskStatus.Completed)
        {
            // 任务完成，返回成功消息
            return Ok(new { status = "completed", model.Id });
        }
        else if (taskStatus.Status == TaskStatus.Failed)
        {
            return BadRequest(new { status = "failed", errorMessage = taskStatus.ErrorMessage });
        }
        else
        {
            // 任务正在进行中
            return Ok(new { status = "running" });
        }
    }
    /// <summary>
    /// 报表-违章关键作业对比-表格
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public async Task<AppResult> TakeTableViolationKeyWorkCheckCount([FromBody] IdInputModel model)
    {
        var tables = TaskManager.GetTaskListTableStatus(model.Id);
        return AppResult.Status200OK(data: tables);
    }
    /// <summary>
    /// 报表-违章关键作业对比-表格
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public async Task<AppResult> TableViolationKeyWorkCheckCount([FromBody] QHSEReportInputModel inputModel)
    {
        var res = await _reportService.TableViolationWorkTypeCheckCount(inputModel);
        return AppResult.Status200OK(data: res);
    }
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public IActionResult StartCompareSelfViolationHSECheckCount([FromBody] QHSEReportInputModel model)
    {
        // 生成唯一任务 ID
        var taskId = Guid.NewGuid().ToString();

        // 将任务状态记录为 "进行中"
        TaskManager.AddCompareTask(taskId, TaskStatus.Running, null);

        // 异步执行导出任务
        Task.Run(() => CompareSelfViolationHSECheckCountAsync(taskId, model));

        // 返回任务 ID
        return Ok(new { taskId });
    }
    private async Task CompareSelfViolationHSECheckCountAsync(string taskId, QHSEReportInputModel model)
    {
        try
        {
            // 调用生成 Excel 的方法
            var excelBytes = await _reportService.CompareSelfViolationHSECheckCount(model);

            // 任务完成，更新状态为完成并保存生成的字节流
            TaskManager.CompleteCompareTask(taskId, excelBytes);
        }
        catch (Exception ex)
        {
            // 任务失败，更新状态为失败并记录错误信息
            TaskManager.FailCompareTask(taskId, ex.Message);
        }
    }
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public IActionResult GetCompareSelfViolationHSECheckCount([FromBody] IdInputModel model)
    {
        // 获取任务状态
        var taskStatus = TaskManager.GetTaskCompareStatus(model.Id);

        // 根据任务状态返回响应
        if (taskStatus.Status == TaskStatus.Completed)
        {
            // 任务完成，返回成功消息
            return Ok(new { status = "completed", model.Id });
        }
        else if (taskStatus.Status == TaskStatus.Failed)
        {
            return BadRequest(new { status = "failed", errorMessage = taskStatus.ErrorMessage });
        }
        else
        {
            // 任务正在进行中
            return Ok(new { status = "running" });
        }
    }
    /// <summary>
    /// 报表-违章体系要素对比-自查
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public async Task<AppResult> TakeCompareSelfViolationHSECheckCount([FromBody] IdInputModel model)
    {
        var tables = TaskManager.GetTaskCompareStatus(model.Id);
        return AppResult.Status200OK(data: tables);
    }
    /// <summary>
    /// 报表-违章体系要素对比-自查
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public async Task<AppResult> CompareSelfViolationHSECheckCount([FromBody] QHSEReportInputModel inputModel)
    {
        var res = await _reportService.CompareSelfViolationHSECheckCount(inputModel);
        return AppResult.Status200OK(data: res);
    }
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public IActionResult StartCompareSuperviseViolationHSECheckCount([FromBody] QHSEReportInputModel model)
    {
        // 生成唯一任务 ID
        var taskId = Guid.NewGuid().ToString();

        // 将任务状态记录为 "进行中"
        TaskManager.AddCompareTask(taskId, TaskStatus.Running, null);

        // 异步执行导出任务
        Task.Run(() => CompareSuperviseViolationHSECheckCountAsync(taskId, model));

        // 返回任务 ID
        return Ok(new { taskId });
    }
    private async Task CompareSuperviseViolationHSECheckCountAsync(string taskId, QHSEReportInputModel model)
    {
        try
        {
            // 调用生成 Excel 的方法
            var excelBytes = await _reportService.CompareSuperviseViolationHSECheckCount(model);

            // 任务完成，更新状态为完成并保存生成的字节流
            TaskManager.CompleteCompareTask(taskId, excelBytes);
        }
        catch (Exception ex)
        {
            // 任务失败，更新状态为失败并记录错误信息
            TaskManager.FailCompareTask(taskId, ex.Message);
        }
    }
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public IActionResult GetCompareSuperviseViolationHSECheckCount([FromBody] IdInputModel model)
    {
        // 获取任务状态
        var taskStatus = TaskManager.GetTaskCompareStatus(model.Id);

        // 根据任务状态返回响应
        if (taskStatus.Status == TaskStatus.Completed)
        {
            // 任务完成，返回成功消息
            return Ok(new { status = "completed", model.Id });
        }
        else if (taskStatus.Status == TaskStatus.Failed)
        {
            return BadRequest(new { status = "failed", errorMessage = taskStatus.ErrorMessage });
        }
        else
        {
            // 任务正在进行中
            return Ok(new { status = "running" });
        }
    }
    /// <summary>
    /// 报表-违章体系要素对比-监督
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public async Task<AppResult> TakeCompareSuperviseViolationHSECheckCount([FromBody] IdInputModel model)
    {
        var tables = TaskManager.GetTaskCompareStatus(model.Id);
        return AppResult.Status200OK(data: tables);
    }
    /// <summary>
    /// 报表-违章体系要素对比-监督
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public async Task<AppResult> CompareSuperviseViolationHSECheckCount([FromBody] QHSEReportInputModel inputModel)
    {
        var res = await _reportService.CompareSuperviseViolationHSECheckCount(inputModel);
        return AppResult.Status200OK(data: res);
    }
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public IActionResult StartTableViolationHSECheckCount([FromBody] QHSEReportInputModel model)
    {
        // 生成唯一任务 ID
        var taskId = Guid.NewGuid().ToString();

        // 将任务状态记录为 "进行中"
        TaskManager.AddListTableTask(taskId, TaskStatus.Running, null);

        // 异步执行导出任务
        Task.Run(() => TableViolationHSECheckCountAsync(taskId, model));

        // 返回任务 ID
        return Ok(new { taskId });
    }
    private async Task TableViolationHSECheckCountAsync(string taskId, QHSEReportInputModel model)
    {
        try
        {
            // 调用生成 Excel 的方法
            var excelBytes = await _reportService.TableViolationHSECheckCount(model);

            // 任务完成，更新状态为完成并保存生成的字节流
            TaskManager.CompleteListTableTask(taskId, excelBytes);
        }
        catch (Exception ex)
        {
            // 任务失败，更新状态为失败并记录错误信息
            TaskManager.FailListTableTask(taskId, ex.Message);
        }
    }
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public IActionResult GetTableViolationHSECheckCountStatus([FromBody] IdInputModel model)
    {
        // 获取任务状态
        var taskStatus = TaskManager.GetTaskListTableStatus(model.Id);

        // 根据任务状态返回响应
        if (taskStatus.Status == TaskStatus.Completed)
        {
            // 任务完成，返回成功消息
            return Ok(new { status = "completed", model.Id });
        }
        else if (taskStatus.Status == TaskStatus.Failed)
        {
            return BadRequest(new { status = "failed", errorMessage = taskStatus.ErrorMessage });
        }
        else
        {
            // 任务正在进行中
            return Ok(new { status = "running" });
        }
    }
    /// <summary>
    /// 报表-违章体系要素对比-表格
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public async Task<AppResult> TakeTableViolationHSECheckCount([FromBody] IdInputModel model)
    {
        var tables = TaskManager.GetTaskListTableStatus(model.Id);
        return AppResult.Status200OK(data: tables);
    }
    /// <summary>
    /// 报表-违章体系要素对比-表格
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public async Task<AppResult> TableViolationHSECheckCount([FromBody] QHSEReportInputModel inputModel)
    {
        var res = await _reportService.TableViolationHSECheckCount(inputModel);
        return AppResult.Status200OK(data: res);
    }
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public IActionResult StartCompareSelfViolationObsCheckCount([FromBody] QHSEReportInputModel model)
    {
        // 生成唯一任务 ID
        var taskId = Guid.NewGuid().ToString();

        // 将任务状态记录为 "进行中"
        TaskManager.AddCompareTask(taskId, TaskStatus.Running, null);

        // 异步执行导出任务
        Task.Run(() => CompareSelfViolationObsCheckCountAsync(taskId, model));

        // 返回任务 ID
        return Ok(new { taskId });
    }
    private async Task CompareSelfViolationObsCheckCountAsync(string taskId, QHSEReportInputModel model)
    {
        try
        {
            // 调用生成 Excel 的方法
            var excelBytes = await _reportService.CompareSelfViolationObsCheckCount(model);

            // 任务完成，更新状态为完成并保存生成的字节流
            TaskManager.CompleteCompareTask(taskId, excelBytes);
        }
        catch (Exception ex)
        {
            // 任务失败，更新状态为失败并记录错误信息
            TaskManager.FailCompareTask(taskId, ex.Message);
        }
    }
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public IActionResult GetCompareSelfViolationObsCheckCount([FromBody] IdInputModel model)
    {
        // 获取任务状态
        var taskStatus = TaskManager.GetTaskCompareStatus(model.Id);

        // 根据任务状态返回响应
        if (taskStatus.Status == TaskStatus.Completed)
        {
            // 任务完成，返回成功消息
            return Ok(new { status = "completed", model.Id });
        }
        else if (taskStatus.Status == TaskStatus.Failed)
        {
            return BadRequest(new { status = "failed", errorMessage = taskStatus.ErrorMessage });
        }
        else
        {
            // 任务正在进行中
            return Ok(new { status = "running" });
        }
    }
    /// <summary>
    /// 报表-违章安全沟通对比-自查
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public async Task<AppResult> TakeCompareSelfViolationObsCheckCount([FromBody] IdInputModel model)
    {
        var tables = TaskManager.GetTaskCompareStatus(model.Id);
        return AppResult.Status200OK(data: tables);
    }
    /// <summary>
    /// 报表-违章安全沟通对比-自查
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public async Task<AppResult> CompareSelfViolationObsCheckCount([FromBody] QHSEReportInputModel inputModel)
    {
        var res = await _reportService.CompareSelfViolationObsCheckCount(inputModel);
        return AppResult.Status200OK(data: res);
    }
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public IActionResult StartCompareSuperviseViolationObsCheckCount([FromBody] QHSEReportInputModel model)
    {
        // 生成唯一任务 ID
        var taskId = Guid.NewGuid().ToString();

        // 将任务状态记录为 "进行中"
        TaskManager.AddCompareTask(taskId, TaskStatus.Running, null);

        // 异步执行导出任务
        Task.Run(() => CompareSuperviseViolationObsCheckCountAsync(taskId, model));

        // 返回任务 ID
        return Ok(new { taskId });
    }
    private async Task CompareSuperviseViolationObsCheckCountAsync(string taskId, QHSEReportInputModel model)
    {
        try
        {
            // 调用生成 Excel 的方法
            var excelBytes = await _reportService.CompareSuperviseViolationObsCheckCount(model);

            // 任务完成，更新状态为完成并保存生成的字节流
            TaskManager.CompleteCompareTask(taskId, excelBytes);
        }
        catch (Exception ex)
        {
            // 任务失败，更新状态为失败并记录错误信息
            TaskManager.FailCompareTask(taskId, ex.Message);
        }
    }
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public IActionResult GetCompareSuperviseViolationObsCheckCount([FromBody] IdInputModel model)
    {
        // 获取任务状态
        var taskStatus = TaskManager.GetTaskCompareStatus(model.Id);

        // 根据任务状态返回响应
        if (taskStatus.Status == TaskStatus.Completed)
        {
            // 任务完成，返回成功消息
            return Ok(new { status = "completed", model.Id });
        }
        else if (taskStatus.Status == TaskStatus.Failed)
        {
            return BadRequest(new { status = "failed", errorMessage = taskStatus.ErrorMessage });
        }
        else
        {
            // 任务正在进行中
            return Ok(new { status = "running" });
        }
    }
    /// <summary>
    /// 报表-违章安全沟通对比-自查
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public async Task<AppResult> TakeCompareSuperviseViolationObsCheckCount([FromBody] IdInputModel model)
    {
        var tables = TaskManager.GetTaskCompareStatus(model.Id);
        return AppResult.Status200OK(data: tables);
    }
    /// <summary>
    /// 报表-违章安全沟通对比-监督
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public async Task<AppResult> CompareSuperviseViolationObsCheckCount([FromBody] QHSEReportInputModel inputModel)
    {
        var res = await _reportService.CompareSuperviseViolationObsCheckCount(inputModel);
        return AppResult.Status200OK(data: res);
    }
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public IActionResult StartTableViolationObsCheckCount([FromBody] QHSEReportInputModel model)
    {
        // 生成唯一任务 ID
        var taskId = Guid.NewGuid().ToString();

        // 将任务状态记录为 "进行中"
        TaskManager.AddListTableTask(taskId, TaskStatus.Running, null);

        // 异步执行导出任务
        Task.Run(() => TableViolationObsCheckCountAsync(taskId, model));

        // 返回任务 ID
        return Ok(new { taskId });
    }
    private async Task TableViolationObsCheckCountAsync(string taskId, QHSEReportInputModel model)
    {
        try
        {
            // 调用生成 Excel 的方法
            var excelBytes = await _reportService.TableViolationObsCheckCount(model);

            // 任务完成，更新状态为完成并保存生成的字节流
            TaskManager.CompleteListTableTask(taskId, excelBytes);
        }
        catch (Exception ex)
        {
            // 任务失败，更新状态为失败并记录错误信息
            TaskManager.FailListTableTask(taskId, ex.Message);
        }
    }
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public IActionResult GetTableViolationObsCheckCountStatus([FromBody] IdInputModel model)
    {
        // 获取任务状态
        var taskStatus = TaskManager.GetTaskListTableStatus(model.Id);

        // 根据任务状态返回响应
        if (taskStatus.Status == TaskStatus.Completed)
        {
            // 任务完成，返回成功消息
            return Ok(new { status = "completed", model.Id });
        }
        else if (taskStatus.Status == TaskStatus.Failed)
        {
            return BadRequest(new { status = "failed", errorMessage = taskStatus.ErrorMessage });
        }
        else
        {
            // 任务正在进行中
            return Ok(new { status = "running" });
        }
    }
    /// <summary>
    /// 报表-违章安全沟通对比-表格
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public async Task<AppResult> TakeTableViolationObsCheckCount([FromBody] IdInputModel model)
    {
        var tables = TaskManager.GetTaskListTableStatus(model.Id);
        return AppResult.Status200OK(data: tables);
    }
    /// <summary>
    /// 报表-违章安全沟通对比-表格
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    [CustomAuthorize("hdv_qhse_report")]
    public async Task<AppResult> TableViolationObsCheckCount([FromBody] QHSEReportInputModel inputModel)
    {
        var res = await _reportService.TableViolationObsCheckCount(inputModel);
        return AppResult.Status200OK(data: res);
    }
}
